package fox.framework.rpc.converter;

import fox.framework.rpc.message.RpcMessageStatus;
import fox.framework.rpc.server.dispatcher.router.DataBinder;

import java.lang.reflect.Type;

/**
 * @author cuichao
 * @Description: CommonExceptionConverter
 * @Date: create in 2021/2/19 21:30
 */
public class CommonExceptionConverter implements RpcMessageConverter {
    @Override
    public String getConverterName() {
        return RpcMessageStatus.COMMON_EXCEPTION_TYPE;
    }

    @Override
    public boolean hasSupport(String protocol ,String mediaType) {
        return  RpcMessageStatus.COMMON_EXCEPTION_TYPE.equals(mediaType);
    }

    @Override
    public <T> T decode(byte[] source, Class<T> cls) {
        return (T)new String(source);
    }

    @Override
    public Object decode(byte[] source, Type type) {
        return new String(source);
    }

    @Override
    public Object[] decode(byte[] bytes, DataBinder[] dataBinders) {
        return new Object[0];
    }

    @Override
    public byte[] encode(Object object) {
        return object.toString().getBytes();
    }
}
